<?php
namespace Api\Controller;
use Think\Controller;
class OrderController extends BaseController{
  /**
  *获取所有票务订单 get
  *@param: 
  *@return:
  */
  public function getAllTicketOrder(){
    $uid = $this->securityTest();
    $orders = M('ticket_order')
    ->where(array('visitor_id'=>$uid))
    ->order('create_time desc')
    ->select();
    $this->response(array('info'=>$orders),json,200);
  }

  /**
  *获取票务订单详情 get
  *@param: orderId
  *@return:
  */
  public function getTicketOrderDetail(){
    $uid = $this->securityTest();
    $orderId = I('get.orderId');
    if(!$orderId){
      $this->response(array('info'=>'缺少订单号'),json,400);
    }
    $order = M('ticket_order')
    ->field('ticket_order.*,ticket.name')
    ->where(array('ticket_order.id'=>$orderId))
    ->find();
    $this->response(array('info'=>$order),json,200);
  }

  /**
  *获取vip会员种类 get
  *@param: 
  *@return:
  */
  public function getAllVipTypes(){
    $uid = $this->securityTest();
    $types = M('membership')
    ->order('create_time asc')
    ->select();
    $vip_check=M('vip_order')
    ->where(array('visitor_id'=>$uid))
    ->join('membership on membership.id = vip_order.vip_type','left')
    ->field('vip_order.*,membership.title as vip_title')
    ->order('end_time desc')
    ->find();
    $identity='普通用户';
    if($vip_check&&$vip_check['end_time']>time()){
      $identity=$vip_check['vip_title'];
    }
    $this->response(array('info'=>$types,'identity'=>$identity),json,200);
  }

  /**
  *获取vip会员详情 get
  *@param: 
  *@return:
  */
  public function getVipTypeDetail(){
    $uid = $this->securityTest();
    $type = I('get.type');
    if(!$type){
      $this->response(array('info'=>'缺少会员种类参数'),json,400);
    }
    $data = M('membership')
    ->find($type);
    $this->response(array('info'=>$data),json,200);
  }

}